package org.mat.ipaas.ucenter.bff.admin.modules.system;

import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.CommonRestAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @Author scott
 * @since 2018-12-20
 */
@Slf4j
@RestController
@RequestMapping("/sys/common")
public class CommonController {

    @Autowired
    private CommonRestAPI commonRestAPI;

    /**
     * @return
     * @Author 政辉
     */
    @GetMapping("/403")
    public MatApiResponse<?> noauth() {
        return MatApiResponse.fail("没有权限，请联系管理员授权");
    }

    /**
     * 文件上传统一方法
     *
     * @return
     */
    @PostMapping(value = "/upload")
    public MatApiResponse<?> upload() throws Exception {
        MatApiResponse<?> matApiResponse = commonRestAPI.upload();
        return matApiResponse;
    }

    /**
     * 预览图片&下载文件
     * 请求地址：http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
     */
    @GetMapping(value = "/static/**")
    public void view() {
        commonRestAPI.view();
    }

    /**
     * @param modelAndView
     * @return
     * @功能：pdf预览Iframe
     */
    @RequestMapping("/pdf/pdfPreviewIframe")
    public ModelAndView pdfPreviewIframe(ModelAndView modelAndView) {
        return commonRestAPI.pdfPreviewIframe(modelAndView);
    }

}
